package 剑指offer.Month7_07.day16;

public class 丑数 {
    public int GetUglyNumber_Solution(int index) {
        int[] arr = new int[index + 1];
        arr[1] = 1;
        if(index == 0) return 0;
        int p2 = 1,p3 = 1,p5 = 1;
        for (int i = 2; i < arr.length; i++) {
            int num2 = arr[p2] * 2,num3 = arr[p3] * 3,num5 = arr[p5] * 5;
            arr[i] = Math.min(num2,Math.min(num3,num5));
            if(arr[i] == num2) p2++;
            if(arr[i] == num3) p3++;
            if(arr[i] == num5) p5++;
        }
        return arr[index];
    }
}
